package com.neusoft.freshmenapp.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.neusoft.freshmenapp.R;
import com.neusoft.freshmenapp.domain.Student;

import java.util.List;

import static androidx.constraintlayout.widget.StateSet.TAG;

/**
 * 学生适配器
 */
public class ClassmateAdapter extends ArrayAdapter<Student> {
    private int resourceId;
    public ClassmateAdapter(@NonNull Context context, int textViewResourceId, @NonNull List<Student> objects) {
        super(context,  textViewResourceId, objects);
        resourceId = textViewResourceId;
    }


    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        //获取当前Student实例
        Student student =getItem(position);

        //获得view
        View view = LayoutInflater.from(getContext()).inflate(resourceId,parent,false);

        TextView tv_name = view.findViewById(R.id.tv_name);
        //将名字写入视图
        tv_name.setText(student.getName());


        return view;
    }
}
